package com.holyant.goods.dto;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.domain.BaseDto;
import com.ruoyi.common.utils.StringUtils;
import com.holyant.goods.utils.ExtAttrUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * 商品SKUdto
 *
 * @author tswsoft
 * @date 2021-04-06
 */
@Data
@ApiModel("商品SKU")
public class GdsSkuDto extends BaseDto {

    private static final long serialVersionUID = 1L;

    /** sku编号 */
    @Excel(name = "sku编号")
    @ApiModelProperty(value = "sku编号")
    private String code;
    /**
     * 流水号
     */
    private Integer serialNum;

    /** sku名称 */
    @Excel(name = "sku名称")
    @ApiModelProperty(value = "sku名称")
    private String name;

    /**
     * 所属商品编码
     */
    private Long goodsId;

    /** 商品编码 */
    @Excel(name = "商品编码")
    @ApiModelProperty(value = "商品编码")
    private String goodsCode;

    /** 商品条码 */
    @Excel(name = "商品条码")
    @ApiModelProperty(value = "商品条码")
    private String goodsBarcode;

    /** 商品名称 */
    @Excel(name = "商品名称")
    @ApiModelProperty(value = "商品名称")
    private String goodsName;

    private String goodsSpecsUnit;
    /** 商品扩展属性 */
    private String goodsExtAttr;

    /** HsCode */
    @Excel(name = "HsCode")
    @ApiModelProperty(value = "HsCode")
    private String hsCode;

    /** 所属分类id */
    @ApiModelProperty(value = "所属分类id")
    private Long categoryId;

    /** 所属分类名称 */
    @Excel(name = "所属分类")
    @ApiModelProperty(value = "所属分类名称")
    private String categoryName;

    /** 所属分类编码 */
    @Excel(name = "所属分类编码")
    @ApiModelProperty(value = "所属分类编码")
    private String categoryCode;

    /** 品牌id */
    @ApiModelProperty(value = "品牌id")
    private Long brandId;

    /** 品牌名称 */
    @Excel(name = "品牌名称")
    @ApiModelProperty(value = "品牌名称")
    private String brandName;

    /** 计量单位id */
    @ApiModelProperty(value = "计量单位id")
    private Long unitId;

    /** 计量单位名称 */
    @Excel(name = "计量单位名称")
    @ApiModelProperty(value = "计量单位名称")
    private String unitName;

    /** 状态  0 正常 1 停用 */
    @Excel(name = "状态", readConverterExp = "0=正常,1=停用")
    @ApiModelProperty(value = "状态  0 正常 1 停用")
    private String status;

    /** 采购价 */
    @Excel(name = "采购价")
    @ApiModelProperty(value = "采购价")
    private BigDecimal purPrc;

    /** 销售价 */
    @Excel(name = "销售价")
    @ApiModelProperty(value = "销售价")
    private BigDecimal salesPrc;

    /** 保质期(月) */
    @Excel(name = "保质期(月)")
    @ApiModelProperty(value = "保质期(月)")
    private Integer qualityPeriod;

    /** 失效日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "失效日期", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty(value = "失效日期")
    private LocalDate expireDate;

    /** 毛重 */
    @Excel(name = "毛重")
    @ApiModelProperty(value = "毛重")
    private BigDecimal grossWeight;

    /** 净重 */
    @Excel(name = "净重")
    @ApiModelProperty(value = "净重")
    private BigDecimal netWeight;

    /** 体积 */
    @Excel(name = "体积")
    @ApiModelProperty(value = "体积")
    private BigDecimal volume;

    /**
     * 箱规
     */
    @Excel(name = "箱规")
    @ApiModelProperty(value = "箱规")
    private String boxSpec;

    /**
     * 托规
     */
    @Excel(name = "托规")
    @ApiModelProperty(value = "托规")
    private String palletSpec;

    /** 规格 */
    @Excel(name = "规格")
    @ApiModelProperty(value = "规格")
    private String specs;

    /** 发货方式 10-保税区发货 20-香港直邮 30-海外直邮 100-国内发货 */
    @ApiModelProperty(value = "发货方式 10-保税区发货 20-香港直邮 30-海外直邮 100-国内发货")
    private Integer deliveryType;

    /** 原产国 */
    @Excel(name = "原产国")
    @ApiModelProperty(value = "原产国")
    private String originCountry;

    /** 扩展属性 */
    private String extAttr;

    @Excel(name = "扩展属性")
    @ApiModelProperty(value = "扩展属性")
    private String extAttrDisplay;

    /** 是否上架 1 是 0 否 */
    @ApiModelProperty(value = "是否上架 1 是 0 否")
    private String shelfFlag;

    /** 成本价不含税 */
    @ApiModelProperty(value = "成本价不含税")
    private String costPriceObj;

    /** 成本价含税 */
    @ApiModelProperty(value = "成本价含税")
    private String taxCostPriceObj;

    /** 备注 */
    @Excel(name = "备注")
    @ApiModelProperty(value = "备注")
    private String remark;

    private Long supplierId;

    private String supplierName;

    public String getExtAttrDisplay() {
        return ExtAttrUtils.getExtAttrDisplay(this.extAttr);
    }
    /** 商品辅助单位属性结构*/
    private String assistUnitAttr;

    private List<AssistUnit> assistUnitList;

    public List<AssistUnit> getAssistUnitList(){
        List<AssistUnit> reList = new ArrayList<>();
        if (StringUtils.isEmpty(this.assistUnitAttr)) {
            return reList;
        }

        return JSON.parseArray(this.assistUnitAttr, AssistUnit.class);
    }

    public void setAssistUnitList(List<AssistUnit> assistUnitList){
        this.assistUnitList = assistUnitList;
        this.assistUnitAttr = JSON.toJSONString(assistUnitList);
    }

    /**
     * 辅助单位对象
     */
    @Data
    static class AssistUnit{
        /**
         * 单位编码
         */
        private String unitCode;
        /**
         * 单位名称
         */
        private String unitName;
        /**
         * 当前数量
         */
        private Integer curQty;
        /**
         * 换算数量
         */
        private Integer castQty;
        /**
         * 最小单位
         */
        private Integer minUnit;
    }


    /**
     * 系统标签
     */
    private List<GdsGoodsTagDto> systemTagList;

    @Excel(name = "标签")
    private String tagNames;
}
